import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg'
import * as dotenv from 'dotenv'
dotenv.config()
export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1641364288856_1485'

  // add your egg config in here
  config.middleware = ['customError']

  config.mongoose = {
    client: {
      url: process.env.YSGS_LEGO_MONGO_URL || '',
    },
  }
  config.bcrypt = {
    saltRounds: 10,
  }
  config.security = {
    csrf: {
      enable: false,
    },
  }
  config.jwt = {
    secret: 'yujie',
  }
  config.redis = {
    client: {
      port: 6379,
      host: process.env.YSGS_LEGO_RADIS_HOST,
      password: '',
      db: 0,
    },
  }

  const giteeOAuthConfig = {
    client_id: process.env.GITEE_CLIENT_ID,
    client_secret: process.env.GITEE_CLIENT_SECRET,
    redictUrl: 'http://127.0.0.1:7001/api/users/passport/gitee/callback',
    authUrl: 'https://gitee.com/oauth/token?grant_type=authorization_code',
    userApiUrl: 'https://gitee.com/api/v5/user',
  }

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
    giteeOAuthConfig,
  }

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  }
}
